﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace LowLevelGraphics.Filter
{
    /// <summary>
    /// 
    /// </summary>
    public class LonelyPixel : BaseImageFilter
    {
        protected int m_nPixelValue = 8;
        /// <summary>
        /// 
        /// </summary>
        public LonelyPixel()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="LonelyPixel"/> class.
        /// </summary>
        /// <param name="_lonelyPixel">The _lonely pixel.</param>
        internal LonelyPixel(LonelyPixel _lonelyPixel)
        {
        }

        /// <summary>
        /// Gets or sets the pixel value.
        /// </summary>
        /// <value>The pixel value.</value>
        public int PixelValue
        {
            get { return m_nPixelValue; }
            set { m_nPixelValue = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="_bitmap"></param>
        public override UnsafeBitmap Execute(UnsafeBitmap _bitmap)
        {
            UnsafeBitmap bitmap = _bitmap;
            CConvMatrix convMatrix = new CConvMatrix();
            convMatrix.TopLeft = -1;
            convMatrix.TopMid = -1;
            convMatrix.TopRight = -1;
            convMatrix.MidLeft = -1;
            convMatrix.Pixel = m_nPixelValue;
            convMatrix.MidRight = -1;
            convMatrix.BottomLeft = -1;
            convMatrix.BottomMid = -1;
            convMatrix.BottomRight = -1;
            new Convolution3x3(convMatrix).Execute(bitmap);
            return _bitmap;
        }

        /// <summary>
        /// This is used to clone a filter, each filter must implement it's own clone functionality
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            return new LonelyPixel(this);
        }
    }
}
